<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
<?php
namespace Admin\Controller;
use Think\Controller;

class ${className}Controller extends Controller
{
	public function index(){
		$${classNameLower} = D('${className}');
		$count = $${classNameLower} -> count();
		$Page = new \Think\Page($count,10);
		$show = $Page->show();	//分页显示输出
		
		$${classNameLower}List = $${classNameLower} -> limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);
		$this->assign('${classNameLower}List',$${classNameLower}List);
		$this->display('list');
	}
	
	public function add(){
		if(IS_POST){
			$${classNameLower}Model = M('${className}');
			$${classNameLower}Model ->create();
			$flag = $${classNameLower}Model ->add();
			if($flag){
				$this->success(L('SUCCESS_ADD_${className}'),U('index')); 
			}else{
				$this->error(L('ERROR_ADD_${className}'),U('index')); 
			}
		}else{
			$this->display(); 
		}
	}
	
	public function edit(){
		$${classNameLower}Model = M('${className}');
		if(IS_POST){
			$${classNameLower}Model ->create();
			$flag = $${classNameLower}Model ->save();
			if($flag){
				$this->success(L('SUCCESS_SAVE_${className}'),U('index')); 
			}else{
				$this->error(L('ERROR_SAVE_${className}'),U('index')); 
			}
		}else{
			$id = I('id'); 
			$${classNameLower} = $${classNameLower}Model->find($id);
			$this->assign('${classNameLower}', $${classNameLower});
			$this->assign('id',$id);
			$this->display();
		}
	}
	
	public function delete(){
		$${classNameLower}Model = D('${className}');
		$id = I('id'); 
		$flag = $${classNameLower}Model->delete($id);
		if($flag){
			$this->success(L('SUCCESS_DELETE_${className}'), U('index'));
		}else{
			$this->error(L('ERROR_DELETE_${className}'), U('index'));
		}
	}
		
}
